package com.xy.servicemanage.request;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

public class Test {

	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception {
		try {
			String data ="xx=是"+  java.net.URLEncoder.encode("测试","UTF-8");
			String xml=" <xml> <ToUserName><![CDATA[toUser]]></ToUserName> <FromUserName><![CDATA[fromUser]]></FromUserName>  <CreateTime>1348831860</CreateTime> <MsgType><![CDATA[text]]></MsgType> <Content><![CDATA[0]]></Content> <MsgId>1234567890123456</MsgId> </xml>";
			URL url = new URL("http://localhost:8080/request.do?signature=85a2a53d85df17ab2ef0055bd17cb80f46685e3c&timestamp=1394719151&nonce=1731303542");
			HttpURLConnection  conn =(HttpURLConnection ) url.openConnection();
			conn.setRequestMethod("POST");
//			conn.setRequestProperty("Content-type", "text/html; charset=UTF-8");
			conn.setDoOutput(true);
			conn.setRequestProperty("User-Agent", "MSIE");
			conn.connect();
		 	OutputStream wr =  conn.getOutputStream( );
			wr.write(xml.getBytes( ));
			wr.flush(); 
	 BufferedReader rd = new BufferedReader(new InputStreamReader(
					conn.getInputStream()));
			String line;
			StringBuffer sb = new StringBuffer();
			while ((line = rd.readLine()) != null) {
				sb.append(line);
			} 
 			wr.close();
		 	rd.close();
		 	System.out.println(sb.toString());
//			return sb.toString();*/
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
//		return "error";
	}

}
